(function () {
  var orderdata = {
    day365: { orders: '20,301,987', amount: '99834' },
    day90: { orders: '301,987', amount: '9834' },
    day30: { orders: '1,987', amount: '3834' },
    day1: { orders: '987', amount: '834' }
  }
  var nowIndex = 0
  // 这里是自动切换的设置,所以下标从0,开始
  var t = setInterval(function () {
    // console.log(nowIndex);-1
    // attr() 方法设置或返回被选元素的属性值 这里在a标签上已经事先写好了,day365 day90 day30 day1
    // 这里这么写,就是为了获取对应的orderdata中的key值
    var key = $('.filter>a').eq(nowIndex).attr('data-key')
    // console.log(nowIndex);0
    // console.log(key);
    var obj = orderdata[key]
    $('.order .item h4:eq(0)').html(obj.orders)
    $('.order .item h4:eq(1)').html(obj.amount)
    // 修改内容
    $('.filter>a').eq(nowIndex).addClass('active').siblings().removeClass('active')
     nowIndex++
    if (nowIndex == $('.filter>a').length) {
      nowIndex = 0
    }
  }, 2000)

  //点击切换数据
  $('.filter>a').click(function () {
    var key = $(this).attr('data-key')
    nowIndex = $(this).index()
    var obj = orderdata[key]
    $('.order .item h4:eq(0)').html(obj.orders)
    $('.order .item h4:eq(1)').html(obj.amount)

    // 修改高亮
    $(this).addClass('active').siblings().removeClass('active')
  })
})()
